package com.lry.util.tree;

import java.lang.reflect.Field;

/**
 * 
 *
 * @author 李瑞益
 */
public class TreeArithometic<T> extends AbstractTreeArith<T> {
    /**
     * 节点映射
     * @param t 实体对象
     * @return 节点对象
     */
    @Override
    public Object getTreeNode(T t) throws IllegalAccessException {
        TreeNode tree = new TreeNode();
        Class<?> aClass = t.getClass();
        Field[] fields = aClass.getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            String fieldName = field.getName();
            if ("id".equalsIgnoreCase(fieldName)) {
                tree.setId(field.get(t).toString());
            }else if ("name".equalsIgnoreCase(fieldName)) {
                tree.setName(field.get(t).toString());
            }else if ("parentId".equalsIgnoreCase(fieldName)) {
                tree.setParentId(field.get(t).toString());
            }else if ("code".equalsIgnoreCase(fieldName)) {
                tree.setCode(field.get(t).toString());
            }
        }
        return tree;
    }

}
